package com.hhkj.admin.student.controller;

import com.github.pagehelper.PageInfo;
import com.hhkj.admin.student.model.req.SaleStudentReq;
import com.hhkj.admin.student.model.res.SaleStudentRes;
import com.hhkj.admin.student.service.biz.SaleStudentBizService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.excl.utils.ExcelUtils;
import com.ruoyi.common.valid.VPage;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * SaleStudentController
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2024/1/15 10:51
 */
@RequestMapping("/sale/student")
@RestController
public class SaleStudentController extends BaseController {

    @Autowired
    private SaleStudentBizService saleStudentBizService;

    /** 导出学员信息 */
    @PreAuthorize("@ss.hasPermi('sale:studentFree:export')")
    @PostMapping("/free/export")
    public void exportFree(@RequestBody SaleStudentReq req, HttpServletResponse response) {
        Workbook freeExcel = saleStudentBizService.createFreeExcel(req);
        ExcelUtils.downLoadExcel("freeStudent", response, freeExcel);
    }

    /** 免费科目学员列表信息 */
    @PreAuthorize("@ss.hasPermi('sale:studentFree:page')")
    @PostMapping("/free/page")
    public TableDataInfo pagingFree(@Validated(VPage.class) @RequestBody SaleStudentReq req) {
        startPageBody(req);
        PageInfo<SaleStudentRes> pageRes = saleStudentBizService.pagingFree(req);
        return getDataTable(pageRes);
    }
}
